<?php
class CompanyIndustriesController extends AppController {

    public $name = 'CompanyIndustries';

    public function index(){
        $this->CompanyIndustry->recursive = 0;
        $this->set('companyIndustries', $this->paginate());
    }

    public function view($id = null){
        if(!$id){
            $this->Session->setFlash(__('Invalid CompanyIndustry.', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->Response->ajax();
        $this->CompanyIndustry->recursive = 1;
        $this->set('companyIndustry', $this->CompanyIndustry->read(null, $id));
    }

    public function add(){
        if(!empty($this->data)){
            $this->CompanyIndustry->create();
            if($this->CompanyIndustry->save($this->data)){
                $this->Session->setFlash(__('The CompanyIndustry has been saved', true));
            }else{
                $this->Session->setFlash(__('The CompanyIndustry could not be saved. Please, try again.', true));
            }
        }
        $this->redirect(array('action'=>'index'));
    }

    public function edit($id = null){
        if(!$id && empty($this->data)){
            $this->Session->setFlash(__('Invalid CompanyIndustry', true));
            $this->redirect(array('action'=>'index'));
        }
        if(!empty($this->data)){
            if($this->CompanyIndustry->save($this->data)){
                $this->Session->setFlash(__('The CompanyIndustry has been saved', true));
            }else{
                $this->Session->setFlash(__('The CompanyIndustry could not be saved. Please, try again.', true));
            }
            $this->redirect(array('action'=>'index'));
        }
        if(empty($this->data)){
            $this->data = $this->CompanyIndustry->read(null, $id);
            $this->Response->ajax();
        }
    }

    public function check(){
        if(!empty($this->data)){
            $term = $this->CompanyIndustry->findByName($this->data['CompanyIndustry']['name']);
            if(empty($term['CompanyIndustry']['name'])){
                $this->Response->json(true, 'CompanyIndustry name check success', $term, null);
            }else{
                $this->Response->json(false, 'CompanyIndustry name check failure', $term, null);
            }
        }else{
            $this->Response->json(false, 'Invalid CompanyIndustry name check request', null, null);
        }
    }

}
?>